<?php
	require_once("mysql.php");

	if($_POST["params"])
	{		
		$json_str = stripslashes($_POST["params"]);
		$data_in = json_decode($json_str, true);
		$sql = new SQLdb("common_user", "");

		if($data_in)
		{
			switch($data_in["type_query"])
			{
				case "INSERT":
					$qa = $sql->query_array("SELECT `id` FROM message ORDER BY `id` DESC LIMIT 1");
					
					if($qa)
						$id = $qa[0]["id"] + 1;
					else
						$id = 0;

					$name = $data_in["data"][1];
					$email = $data_in["data"][2];
					$title = $data_in["data"][3];
					$text = $data_in["data"][4];

				
					$sql->query("INSERT INTO message (`id`, `name`, `email`, `title`, `text`) VALUES ('$id', '$name', '$email', '$title', '$text')");
					$res["error"] = mysql_error();

					echo json_encode($res);
					break;


			}
		}
	}

?>
